package sword.T57;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author: 18362
 * @Create: 2022-04-10 13:01:43 星期日
 */
public class Solution2 {
    public int[][] findContinuousSequence(int target) {
        if (target == 1)
            return new int[][] {{1}};
        int left = 1, right = 1, sum = 0;
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> path = new LinkedList<>();
        while (right < target) {
            sum += right;
            path.add(right);
            right++;
            while (sum >= target) {
                if (sum == target) {
                    res.add(new ArrayList<>(path));
                }
                sum -= left;
                left++;
                path.remove(0);
            }
        }
        int[][] arr = new int[res.size()][];
        for (int i=0; i<res.size(); ++i) {
            arr[i] = new int[res.get(i).size()];
            for (int j=0; j<arr[i].length; ++j)
                arr[i][j] = res.get(i).get(j);
        }
        return arr;
    }
}
